/**
  This file contains a 'Sample Driver' and is licensed as such
  under the terms of your license agreement with Intel or your
  vendor.  This file may be modified by the user, subject to
  the additional terms of the license agreement

@copyright
  Copyright (c)  2005 - 2012 Intel Corporation. All rights reserved
  This software and associated documentation (if any) is furnished
  under a license and may only be used or copied in accordance
  with the terms of the license. Except as permitted by such
  license, no part of this software or documentation may be
  reproduced, stored in a retrieval system, or transmitted in any
  form or by any means without the express written consent of
  Intel Corporation.

@file
  AlertStandardFormat.h

@brief
  Definition of Alert Standard Format (ASF) 2.0

**/
#ifndef __ALERT_STANDARD_FORMAT_PROTOCOL_H__
#define __ALERT_STANDARD_FORMAT_PROTOCOL_H__

#define EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GUID \
  { \
    0xcc93a70b, 0xec27, 0x49c5, 0x8b, 0x34, 0x13, 0x93, 0x1e, 0xfe, 0xd6, 0xe2 \
  }

typedef struct _EFI_ALERT_STANDARD_FORMAT_PROTOCOL  EFI_ALERT_STANDARD_FORMAT_PROTOCOL;

#pragma pack(1)
typedef struct {
  UINT8   SubCommand;
  UINT8   Version;
  UINT32  IanaId;
  UINT8   SpecialCommand;
  UINT16  SpecialCommandParam;
  UINT16  BootOptions;
  UINT16  OemParameters;
} EFI_ASF_BOOT_OPTIONS;

typedef struct {
  UINT8 SubCommand;
  UINT8 Version;
  UINT8 EventSensorType;
  UINT8 EventType;
  UINT8 EventOffset;
  UINT8 EventSourceType;
  UINT8 EventSeverity;
  UINT8 SensorDevice;
  UINT8 SensorNumber;
  UINT8 Entity;
  UINT8 EntityInstance;
  UINT8 Data0;
  UINT8 Data1;
} EFI_ASF_MESSAGE;

typedef struct {
  UINT8 SubCommand;
  UINT8 Version;
} EFI_ASF_CLEAR_BOOT_OPTIONS;
#pragma pack()
//
// Special Command Attributes
//
#define NOP               0x00
#define FORCE_PXE         0x01
#define FORCE_HARDDRIVE   0x02
#define FORCE_SAFEMODE    0x03
#define FORCE_DIAGNOSTICS 0x04
#define FORCE_CDDVD       0x05

//
// Boot Options Mask
//
#define LOCK_POWER_BUTTON             0x0002  ///< 0000 0000 0000 0010 - bit 1
#define LOCK_RESET_BUTTON             0x0004  ///< 0000 0000 0000 0200 - bit 2
#define LOCK_KEYBOARD                 0x0020  ///< 0000 0000 0010 0000 - bit 5
#define LOCK_SLEEP_BUTTON             0x0040  ///< 0000 0000 0100 0000 - bit 6
#define USER_PASSWORD_BYPASS          0x0800  ///< 0000 1000 0000 0000 - bit 3
#define FORCE_PROGRESS_EVENTS         0x1000  ///< 0001 0000 0000 0000 - bit 4
#define FIRMWARE_VERBOSITY_DEFAULT    0x0000  ///< 0000 0000 0000 0000 - bit 6:5
#define FIRMWARE_VERBOSITY_QUIET      0x2000  ///< 0010 0000 0000 0000 - bit 6:5
#define FIRMWARE_VERBOSITY_VERBOSE    0x4000  ///< 0100 0000 0000 0000 - bit 6:5
#define FIRMWARE_VERBOSITY_BLANK      0x6000  ///< 0110 0000 0000 0000 - bit 6:5
#define CONFIG_DATA_RESET             0x8000  ///< 1000 0000 0000 0000 - bit 7
#define ASF_BOOT_OPTIONS_PRESENT      0x16
#define ASF_BOOT_OPTIONS_NOT_PRESENT  0x17

#define USE_KVM                       0x0020  ///< 0000 0000 0010 0000 - bit 5
///
/// ASF Internet Assigned Numbers Authority Manufacturer ID
/// (The firmware sends 0XBE110000 for decimal value 4542)
///
#define INDUSTRY_IANA_SWAP32(x)       ((((x) & 0xff) << 24) | (((x) & 0xff00) << 8) | \
                                        (((x) & 0xff0000) >> 8) | (((x) & 0xff000000) >> 24))
#define ASF_INDUSTRY_IANA             0x000011BE
#define ASF_INDUSTRY_CONVERTED_IANA   INDUSTRY_IANA_SWAP32 (ASF_INDUSTRY_IANA)  ///< 0XBE110000, received from ME FW

typedef
EFI_STATUS
(EFIAPI *EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GET_SMBUSADDR) (
  IN  EFI_ALERT_STANDARD_FORMAT_PROTOCOL   * This,
  OUT UINTN                                *SmbusDeviceAddress
  )
/**

  Return the SMBus address used by the ASF driver.

  @retval EFI_SUCCESS             Address returned
  @retval EFI_INVALID_PARAMETER   Invalid SMBus address

**/
;

typedef
EFI_STATUS
(EFIAPI *EFI_ALERT_STANDARD_FORMAT_PROTOCOL_SET_SMBUSADDR) (
  IN  EFI_ALERT_STANDARD_FORMAT_PROTOCOL   * This,
  IN  UINTN                                SmbusDeviceAddress
  )
/**

  Set the SMBus address used by the ASF driver. 0 is an invalid address.

  @param[in] SmbusAddr            SMBus address of the controller

  @retval EFI_SUCCESS             Address set
  @retval EFI_INVALID_PARAMETER   Invalid SMBus address

**/
;

typedef
EFI_STATUS
(EFIAPI *EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GET_BOOT_OPTIONS) (
  IN      EFI_ALERT_STANDARD_FORMAT_PROTOCOL   * This,
  IN  OUT EFI_ASF_BOOT_OPTIONS                 **AsfBootOptions
  )
/**

  Return the ASF Boot Options obtained from the controller. If the
  Boot Options parameter is NULL and no boot options have been retrieved,
  Query the ASF controller for its boot options.

  @param[in] AsfBootOptions       Pointer to ASF boot options to copy current ASF Boot options

  @retval EFI_SUCCESS             Boot options copied
  @retval EFI_NOT_READY           No boot options

**/
;

typedef
EFI_STATUS
(EFIAPI *EFI_ALERT_STANDARD_FORMAT_PROTOCOL_SEND_ASF_MESSAGE) (
  IN  EFI_ALERT_STANDARD_FORMAT_PROTOCOL   * This,
  IN  EFI_ASF_MESSAGE                      * AsfMessage
  )
/**

  Send ASF Message.

  @param[in] AsfMessage           Pointer to ASF message

  @retval EFI_SUCCESS             Boot options copied
  @retval EFI_INVALID_PARAMETER   Invalid pointer
  @retval EFI_NOT_READY           No controller

**/
;

typedef struct _EFI_ALERT_STANDARD_FORMAT_PROTOCOL {
  EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GET_SMBUSADDR    GetSmbusAddr;
  EFI_ALERT_STANDARD_FORMAT_PROTOCOL_SET_SMBUSADDR    SetSmbusAddr;
  EFI_ALERT_STANDARD_FORMAT_PROTOCOL_GET_BOOT_OPTIONS GetBootOptions;
  EFI_ALERT_STANDARD_FORMAT_PROTOCOL_SEND_ASF_MESSAGE SendAsfMessage;
} EFI_ALERT_STANDARD_FORMAT_PROTOCOL;

extern EFI_GUID gEfiAlertStandardFormatProtocolGuid;

#endif
